<?php
namespace app\erp\model;

use think\Model;

class Systemdb extends Model
{

    protected $name = 'system';

    public $param = array();

    public function getSys()
    {
        $data = $this->find();
        if ($data) {
            $data = $data->toArray();
            $this->param['system_id'] = $data['system_id'];
            if ($data['system_flag'] == 1) {
                $this->allowField(true)->save($this->param, array(
                    'system_id' => $data['system_id']
                ));
                return true;
            } else {
                return $this->chkInfo($data['system_json'], $data['system_id']);
            }
        } else {
            $this->allowField(true)->save($this->param);
            return true;
        }
    }

    protected function chkInfo($data, $system_id)
    {
        if ($data == $this->param['system_json']) {
            return true;
        } else {
            $this->allowField('last_json')->save(array(
                'last_json' => $this->param['system_json']
            ), array(
                'system_id' => $system_id
            ));
            exit(lang('file_changed'));
            return lang('file_changed');
        }
    }
}